final _nobleGases = {};

bool isNoble(int atomicNumber) {
  return _nobleGases[atomicNumber] != null;
}

isNoble2 (atomicNumber) {
  return _nobleGases[atomicNumber] != null;
}

bool isNoble3(int atomicNumber) => _nobleGases[atomicNumber] != null;

// 可选参数
// 命名可选参数
void enableFlags({bool bold, bool hidden}) {
  print('$bold, $hidden');
}
// 位置可选参数
void say(String from, String msg, [String device]) {
  var result = '$from says $msg';
  if (device != null) {
    result = '$result with a $device';
  }
  print(result);
}
// 默认参数值
void enableFlags2({bool bold = false, bool hidden = false}) {
  print('$bold, $hidden');
}
// 位置参数设置默认值
void say2(String from, String msg, [String device = 'carrier pigeon', String mood]) {
  var result = '$from says $msg';
  if (device != null) {
    result = '$result with a $device';
  }
  if (mood != null) {
    result = '$result (in a $mood mood)';
  }
  print(result);
}

void doStuff({
  List<int> list = const [1, 2, 3],
  Map<String, String> gifts = const {
    'first': 'paper',
    'second': 'cotton',
    'third': 'leather'
  }
}) {
  print('list:  $list');
  print('gifts: $gifts');
}

// 函数是一等对象
void printElement(int element) {
  print(element);
}
var loudify = (msg) => '!!! ${msg.toUpperCase()} !!!';

bool topLevel = true;

main (List<String> arguments) {
  enableFlags(bold: false);
  enableFlags(bold: true, hidden: false);
  say('Bob', 'Howdy');
  say('Bob', 'Howdy', 'smoke signal');
  enableFlags2(bold: true);
  say2('Bob', 'Howdy');
  say2('Bob', 'Howdy', null, 'xxx');
  doStuff();

  // dart day11.dart 1 test
  // print(arguments);

  // print(arguments.length == 2);
  // print(int.parse(arguments[0]) == 1);
  // print(arguments[1] == 'test');

  [1, 2, 3].forEach(printElement);
  print(loudify('hello') == '!!! HELLO !!!');
  ['apples', 'bananas', 'oranges'].forEach((item) {
    print('$item');
  });
  // 如果函数只有一条语句， 可以使用箭头简写。
  ['apples', 'bananas', 'oranges'].forEach((item) => print('$item'));

  var insideMain = true;

  void myFunction() {
    var insideFunction = true;

    void nestedFunction() {
      var insideNestedFunction = true;

      assert(topLevel);
      assert(insideMain);
      assert(insideFunction);
      assert(insideNestedFunction);
    }
  }
}